package com.example.demo.config;

import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.ExternalDocumentation;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import io.swagger.v3.oas.models.security.SecurityScheme;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class SpringDocConfig {
    private static final String SECURITY_SCHEME_NAME = "BearerAuth";

    @Bean
    public OpenAPI OpenApi() {

        OpenAPI openApi = new OpenAPI();
        openApi.info(new Info().title("demo")
                .contact(new Contact())
                .description("学习小demo")
                .version("v1.0.0")
                .license(new License().name("Apache 2.0").url("http://springdoc.org")));
        openApi.externalDocs(new ExternalDocumentation()
                .description("后续更新csdn博客")
                .url("https://springshop.wiki.github.org/docs"));

//        openApi.addSecurityItem(new SecurityRequirement().addList(SECURITY_SCHEME_NAME));
        openApi.components(new Components()
                .addSecuritySchemes(SECURITY_SCHEME_NAME
                        , new SecurityScheme()
                                .name("Authorization")
                                .type(SecurityScheme.Type.HTTP)
                                .scheme("Bearer")
                                .bearerFormat("JWT")
                                .in(SecurityScheme.In.HEADER)));
        return openApi;
    }

}
